// KnownPartSet.cpp: implementation of the KnownPartSet class.
//
//////////////////////////////////////////////////////////////////////

#include "stdafx.h"
#include "KnownPartSet.h"
#include "ProjectManager.h"

//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////

KnownPartSet::KnownPartSet()
{

}

KnownPartSet::~KnownPartSet()
{

}

PartSortPropertySet* KnownPartSet::GetPartSortPropertySet(const CString& strStandard)
{
	ASSERT(!strStandard.IsEmpty());
	PartSortPropertySet* pSet = NULL;

	pSet = this->GetManaged(strStandard);
	
	return pSet;
}

void KnownPartSet::AddSortProperty(PartSortProperty * pProperty)
{
	ASSERT(pProperty);
	PartSortPropertySet *pPropertySet = this->GetManaged(pProperty->Standard());
	if( pPropertySet != NULL )
	{
		pPropertySet->Add(pProperty->CustomID(),pProperty);
		return;
	}

	pPropertySet = new PartSortPropertySet;
	ASSERT(pPropertySet);
	this->Add(pProperty->Standard(),pPropertySet);
	pPropertySet->SetStandard(pProperty->Standard());
	pPropertySet->Add(pProperty->CustomID(),pProperty);
}

void KnownPartSet::RemoveSortProperty(PartSortProperty *pProperty)
{
	ASSERT(pProperty);

	PartSortPropertySet * pPropertySet = NULL;

	pPropertySet = this->GetManaged(pProperty->Standard());
	ASSERT(pPropertySet);
	pPropertySet->DeleteItem(pProperty->CustomID());
	if( pPropertySet->GetElementCount() == 0 )
		this->DeleteItem(pProperty->Standard());
}

KnownPartSet& KnownPartSet::Instance()
{
	ASSERT(GetProjectManager().CurProject());
	return GetProjectManager().CurProject()->SPQManager().GetCustomIDQuery();
}